package com.zhu.wx.facade;

import com.zhu.wx.dict.WxResEnum;
import com.zhu.wx.entity.ResMsg;
import com.zhu.wx.factory.Factory;
import com.zhu.wx.factory.StrategyFactory;
import com.zhu.wx.strategy.ResStrategyContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 外观
 * 作用：外观模式（Facade Pattern）隐藏系统的复杂性，
 * 并向客户端提供了一个客户端可以访问系统的接口。
 */
@Component
public class ResStrategyFacade {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 外观模式不参与子系统的逻辑，所以对子系统进行了一次封装
     */
    private Factory factory = new StrategyFactory();
    private ResStrategyContext context = new ResStrategyContext(null);

    public ResStrategyFacade() {
    }

    public String execute(ResMsg resMsg, WxResEnum strategy) {
        this.context.setStrategy(this.factory.createStrategy(strategy));
        logger.info("结果处理策略选择 - {}", strategy.getDesc());
        String execute = this.context.execute(resMsg);
        logger.info("{} - 结果处理策略返回 - {}", strategy.getDesc(), execute);
        return execute;
    }

}
